added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / jswrappedfield.cs
blob6755b61603d92f2785c1e014c780dcc92f2fc542
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
17 This class allows JSObjects to return fields that are not their own, as if they were. Think of it as a field "delegate".
21 namespace Microsoft.JScript {
23 using System;
24 using System.Globalization;
25 using System.Reflection;
27 internal sealed class JSWrappedField : JSField, IWrappedMember{
28 internal FieldInfo wrappedField;
29 internal Object wrappedObject;
31 internal JSWrappedField(FieldInfo field, Object obj){
32 if (field is JSFieldInfo) field = ((JSFieldInfo)field).field;
33 this.wrappedField = field;
34 this.wrappedObject = obj;
35 if (obj is JSObject && !Typeob.JSObject.IsAssignableFrom(field.DeclaringType))
36 if (obj is BooleanObject) this.wrappedObject = ((BooleanObject)obj).value;
37 else if (obj is NumberObject) this.wrappedObject = ((NumberObject)obj).value;
38 else if (obj is StringObject) this.wrappedObject = ((StringObject)obj).value;
41 public override String Name{
42 get{
43 return this.wrappedField.Name;
47 public override FieldAttributes Attributes{
48 get{
49 return this.wrappedField.Attributes;
53 public override Type DeclaringType{
54 get{
55 return this.wrappedField.DeclaringType;
59 public override Type FieldType{
60 get{
61 return this.wrappedField.FieldType;
65 internal override String GetClassFullName(){
66 if (this.wrappedField is JSField)
67 return ((JSField)this.wrappedField).GetClassFullName();
68 else
69 return this.wrappedField.DeclaringType.FullName;
72 internal override Object GetMetaData(){
73 if (this.wrappedField is JSField)
74 return ((JSField)this.wrappedField).GetMetaData();
75 else
76 return this.wrappedField;
79 internal override PackageScope GetPackage(){
80 if (this.wrappedField is JSField){
81 return ((JSField)this.wrappedField).GetPackage();
83 return null;
86 public override Object GetValue(Object obj){
87 return this.wrappedField.GetValue(this.wrappedObject);
90 public Object GetWrappedObject(){
91 return this.wrappedObject;
94 public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo locale){
95 this.wrappedField.SetValue(this.wrappedObject, value, invokeAttr, binder, locale);